<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 6/19/17
 * Time: 4:06 PM
 */

/**
 * auth创建
 * @param $pass
 * @return bool
 */
function auth($pass)
{
    if ($pass == DEF_PASS) {
        setcookie('login', time());
        return true;
    } else {
        return false;
    }
}


/**
 * auth认证
 * @return bool
 */
function authCheck()
{
    if (!$_COOKIE['login'] || (time() - $_COOKIE['login']) > 3600) {
        return false;
    } else {
        return true;
    }
}

/**
 * 返回信息
 * @param $msg
 * @param int $status
 * @param array $data
 * @return string
 */
function msg($msg, $status = 1, $data = [])
{
    $arr['msg'] = $msg;
    $arr['status'] = $status;
    $arr['data'] = $data;
    echo json_encode($arr);
    exit;
}
